package com.czy.owner.ui.order;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.adapter.BaseRecyclerAdapter;
import com.czy.owner.adapter.OrderCouponAdapter;
import com.czy.owner.adapter.OrderDetailsGoodsAdapter;
import com.czy.owner.callback.RecycleViewDivider;
import com.czy.owner.entity.OrderCouponsListModel;
import com.czy.owner.global.Constants;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.utils.PhoneUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by hedepu on 2017-09-08
 */

public class PicCouponActivity extends BaseActivity {
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar_subtitle)
    TextView toolbarSubtitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.elv_coupon)
    RecyclerView elvCoupon;
    OrderCouponAdapter orderCouponAdapter;
    private List<OrderCouponsListModel> list = new ArrayList<>();
    private int isPosition;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_pic_coupon;
    }

    @Override
    protected void initInjector() {
        list = (List<OrderCouponsListModel>) getIntent().getSerializableExtra("couponList");
        isPosition = getIntent().getIntExtra("isPosition", -1);
    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText("选择优惠券");
        getSubTitle().setText("确定");
        elvCoupon.setLayoutManager(new LinearLayoutManager(this));
        orderCouponAdapter = new OrderCouponAdapter(this, list);
        elvCoupon.setAdapter(orderCouponAdapter);
        orderCouponAdapter.setIsPosition(isPosition);
//        elvCoupon.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL, R.drawable.shape_gray_divider_decoration));
        orderCouponAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, Object o, View view) {
                if (position == orderCouponAdapter.getIsPosition())
                    orderCouponAdapter.setIsPosition(-1);
                else
                    orderCouponAdapter.setIsPosition(position);
            }
        });
    }

    @OnClick(R.id.toolbar_subtitle)
    public void sure(View view) {
        Intent intent = new Intent();
//        intent.putStringArrayListExtra(Constants.TRANSMISSION_CONTENT_KEY, "");
        intent.putExtra("couponsModel", orderCouponAdapter.getIsPosition() == -1 ? null : list.get(orderCouponAdapter.getIsPosition()));
        intent.putExtra("isPosition", orderCouponAdapter.getIsPosition());
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    protected void updateViews() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
